<?php
    
//    require_once('DBI.class.php');
//    require_once('dbUtil.php');
    require_once('Debug.lib.php');
  
    require_once('Audit.lib.php');
    
    class MODEL_CMS_Base {
        protected $log_name = 'cms';
        private   $dbh_r=null;
        private   $dbh_w=null;
        protected $enable_audit = 1;
        
        function log_error($message){
            if ($this->enable_audit != 1){
                return;
            }
            #$log_name = 'payment_error_'.$this->log_name;
            #echo "$log_name: $message\n";
            #debug_log('payment', "$log_name: $message");
            #?#$prefix = 'error_'.$this->log_name;
            #?#audit_log('CMS_Base', $prefix.': '.$message);
        }
        function log_operation($message){
            if ($this->enable_audit != 1){
                return;
            }
            #$log_name = 'payment_operation_'.$this->log_name;
            #echo "$log_name: $message\n";
            #debug_log('payment', "$log_name: $message");
            #?#$prefix = 'operation_'.$this->log_name;
            #?#audit_log('CMS_Base', $prefix.': '.$message);
        }
        
        # centralize the db connection class
        function db_connect($mode='read'){
            if ($mode == 'write'){
                if ($this->dbh_w == null){
                    $db = new DBI('write');
                    $this->dbh_w = $db->connect();
                }
                return $this->dbh_w;
            }
            
            if ($this->dbh_r == null){
                $db = new DBI('read');
                $this->dbh_r = $db->connect();   
            }
            return $this->dbh_r;
        } 
        
        
/*        function send_mail($mid, $email_type, $h_param_in=array()){
            require_once 'GMC.class.php';
            $h_param['mid'] = $mid;
            $h_param['email_type'] = $email_type;
            $h_param['h_param'] = $h_param_in;
            
            $gmc = new GMC;
            $gmc->job_do('send_email', $h_param);
        }
 */
        
    }
    ?>